package vista;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaAgregarLinea extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JPanel panAgregarLinea;
	private JLabel lblCodigoLinea;
	private JTextField txtDescripcionLinea;
	private JButton btnSalirLinea;
	private JButton btnCancelarLinea;
	private JButton btnRegistrarLinea;
	private JButton btnBuscarLinea;
	private JLabel lblDescripcionLinea;
	private JTextField txtCodigoLinea;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				VentanaAgregarLinea inst = new VentanaAgregarLinea();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public VentanaAgregarLinea() {
		super();
		initGUI();
	}
	
	public void agregarListener(ActionListener accion){
		
		
		/*Agregamos todos los Action Listener para que ejecuten el evento*/
		btnRegistrarLinea.addActionListener(accion);
		btnSalirLinea.addActionListener(accion);
		btnCancelarLinea.addActionListener(accion);
		btnBuscarLinea.addActionListener(accion);
		
		
		}
	
		/*********************************************
		public void foco(){
			txtCedulaCliente.transferFocus();
		}*/
		
		
		public void setCodigo(String cod){
			txtCodigoLinea.setText(cod);
		}
		
		public void setDescripcion(String desc){
			txtDescripcionLinea.setText(desc);
		}
	
		public String getCodigo(){
			return txtCodigoLinea.getText();
		}
		
		public String getDescripcion(){
			return txtDescripcionLinea.getText();
		}
		
		
		public void limpiarCampos(){
			txtCodigoLinea.setText("");
			txtDescripcionLinea.setText("");
		}
		
		public void mostrarMensaje(String mensaje) {
			JOptionPane.showMessageDialog(this, mensaje);
		}
		
		public void inhabilitar(){
			txtCodigoLinea.enable(false);	
		}
		
		public void habilitar(){
			txtCodigoLinea.enable(true);
		}
		
		
		public Boolean validar(){
			
			if (txtCodigoLinea.getText().isEmpty()== true){
				mostrarMensaje("Ingrese la Código de la Línea");		
				return false;
			}
			else
				if(txtDescripcionLinea.getText().isEmpty()== true){
				mostrarMensaje("Ingrese Descripción de la Línea")	;
				return false;
			}	
			 else
			      return true;		
		}
		
			
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				panAgregarLinea = new JPanel();
				getContentPane().add(panAgregarLinea, "Center");
				panAgregarLinea.setBounds(0, 0, 390, 270);
				panAgregarLinea.setLayout(null);
				{
					lblCodigoLinea = new JLabel();
					panAgregarLinea.add(lblCodigoLinea);
					lblCodigoLinea.setText("Codigo:");
					lblCodigoLinea.setBounds(44, 32, 47, 15);
				}
				{
					txtCodigoLinea = new JTextField();
					panAgregarLinea.add(txtCodigoLinea);
					txtCodigoLinea.setBounds(103, 25, 101, 27);
				}
				{
					lblDescripcionLinea = new JLabel();
					panAgregarLinea.add(lblDescripcionLinea);
					lblDescripcionLinea.setText("Descripcion:");
					lblDescripcionLinea.setBounds(44, 79, 86, 17);
				}
				{
					txtDescripcionLinea = new JTextField();
					panAgregarLinea.add(txtDescripcionLinea);
					txtDescripcionLinea.setBounds(136, 74, 158, 27);
				}
				{
					btnBuscarLinea = new JButton();
					panAgregarLinea.add(btnBuscarLinea);
					btnBuscarLinea.setText("Buscar");
					btnBuscarLinea.setBounds(216, 25, 71, 27);
					btnBuscarLinea.setActionCommand("Buscar");
				}
				{
					btnRegistrarLinea = new JButton();
					panAgregarLinea.add(btnRegistrarLinea);
					btnRegistrarLinea.setText("Registrar");
					btnRegistrarLinea.setBounds(22, 155, 85, 27);
					//btnRegistrarLinea.setActionCommand("Registrar");
					//btnRegistrarLinea.addActionListener(this);
				}
				{
					btnCancelarLinea = new JButton();
					panAgregarLinea.add(btnCancelarLinea);
					btnCancelarLinea.setText("Cancelar");
					btnCancelarLinea.setBounds(146, 155, 83, 27);
					btnCancelarLinea.setActionCommand("Cancelar");
				}
				{
					btnSalirLinea = new JButton();
					panAgregarLinea.add(btnSalirLinea);
					btnSalirLinea.setText("Salir");
					btnSalirLinea.setBounds(271, 155, 55, 27);
					btnSalirLinea.setActionCommand("Salir");
				}
			}
			pack();
			setSize(400, 300);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
